package com.lmabbe.common.datasources.handle;

import com.lmabbe.common.global.context.TenantBuildContext;
import org.springframework.context.ApplicationContext;

/**
 * 初始化Application工厂，生成处理链
 *
 * @author lmabbe
 */
@SuppressWarnings("ALL")
public class InitApplicationFactory {


    /**
     * 创建核心应用初始化链条
     *
     * @param applicationContext
     * @param tenantContext
     * @return
     */
    public static InitApplicationHandle createCoreServiceChain(ApplicationContext applicationContext, TenantBuildContext tenantContext) {
        InitConnectPoolHandler initConnectPoolHandler = new InitConnectPoolHandler(applicationContext, tenantContext);

        SyncDdlHandle syncDdlHandle = new SyncDdlHandle(applicationContext, tenantContext);
        initConnectPoolHandler.setNext(syncDdlHandle);

        InitSystemDataHandle initSystemDataHandle = new InitSystemDataHandle(applicationContext, tenantContext);
        syncDdlHandle.setNext(initSystemDataHandle);

        LoadSystemDateHandle loadSystemDateHandle = new LoadSystemDateHandle(applicationContext, tenantContext);
        initSystemDataHandle.setNext(loadSystemDateHandle);

        loadSystemDateHandle.setNext(null);
        return initConnectPoolHandler;
    }


    /**
     * 创建核心应用初始化链条
     *
     * @param applicationContext
     * @param tenantContext
     * @return
     */
    public static InitApplicationHandle createNotCoreServiceChain(ApplicationContext applicationContext, TenantBuildContext tenantContext) {
        InitConnectPoolHandler initConnectPoolHandler = new InitConnectPoolHandler(applicationContext, tenantContext);

        LoadSystemDateHandle loadSystemDateHandle = new LoadSystemDateHandle(applicationContext, tenantContext);
        initConnectPoolHandler.setNext(loadSystemDateHandle);

        initConnectPoolHandler.setNext(null);
        return initConnectPoolHandler;
    }


    /**
     * 创建Mq租户升级链条
     *
     * @param applicationContext
     * @param tenantContext
     * @return
     */
    public static InitApplicationHandle createMqChain(ApplicationContext applicationContext, TenantBuildContext tenantContext) {
        InitConnectPoolHandler initConnectPoolHandler = new InitConnectPoolHandler(applicationContext, tenantContext);

        LoadSystemDateHandle loadSystemDateHandle = new LoadSystemDateHandle(applicationContext, tenantContext);
        initConnectPoolHandler.setNext(loadSystemDateHandle);

        initConnectPoolHandler.setNext(null);
        return initConnectPoolHandler;
    }


    /**
     * 创建租户初始化链条
     *
     * @param applicationContext
     * @param tenantContext
     * @return
     */
    public static InitApplicationHandle createInitTenantChain(ApplicationContext applicationContext, TenantBuildContext tenantContext) {
        InitConnectPoolHandler initConnectPoolHandler = new InitConnectPoolHandler(applicationContext, tenantContext);

        SyncDdlHandle syncDdlHandle = new SyncDdlHandle(applicationContext, tenantContext);
        initConnectPoolHandler.setNext(syncDdlHandle);

        InitTenantBaseDataHandle tenantBaseDataHandle = new InitTenantBaseDataHandle(applicationContext,tenantContext);
        syncDdlHandle.setNext(tenantBaseDataHandle);

        InitSystemDataHandle initSystemDataHandle = new InitSystemDataHandle(applicationContext, tenantContext);
        tenantBaseDataHandle.setNext(initSystemDataHandle);

        LoadSystemDateHandle loadSystemDateHandle = new LoadSystemDateHandle(applicationContext, tenantContext);
        initSystemDataHandle.setNext(loadSystemDateHandle);

        loadSystemDateHandle.setNext(null);
        return initConnectPoolHandler;
    }



}
